/*gcc -c -o gtkEbox.o gtkEbox.c `pkg-config --cflags --libs gtk+-2.0`*/
#include "mygtk.h"
#include <gtk/gtk.h>
#include <stdio.h>

int show_popup(GtkWidget *widget, GdkEvent *event);

Widget_t *createEbox()
{
	GtkWidget *eBox;
	eBox = gtk_event_box_new();
	return eBox;
}

void addItemToEbox(Widget_t *eBox, Widget_t *item[], int num)
{
	GtkWidget *pmenu;
	pmenu = gtk_menu_new();
	for (int i = 0; i < num; ++i) {
		gtk_widget_show(item[i]);
		gtk_menu_shell_append(GTK_MENU_SHELL(pmenu), item[i]);
	}
	g_signal_connect_swapped(G_OBJECT(eBox), "button_press_event", G_CALLBACK(show_popup), pmenu);
}

int show_popup(GtkWidget *widget, GdkEvent *event)
{
	const gint RIGHT_CLICK = 3;
	if (event->type == GDK_BUTTON_PRESS) {
		GdkEventButton *bevent = (GdkEventButton *) event;
		if (bevent->button == RIGHT_CLICK)
			gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
		return TRUE;
	}
	return FALSE;
}